<template>
	<view>
		<template v-if="!loginStatus">
			<!-- 未登录 -->
			<view class="m-f-jcc">登陆仿糗百，体验更多功能</view>
			<!-- 第三方登录 -->
			<other-login :noback="true" @logining="isLogin()"></other-login>
			<!-- 账号密码登录 -->
			<view class="m-f-jcc" @tap="openLogin">
				账号密码登陆
				<view class="icon iconfont icon-qianjinxiayige"></view>
			</view>
		</template>
		<template v-else>
			<!-- 登录 -->
			<home-info :homeinfo="homeinfo"></home-info>
		</template>
		
		<!-- 数据 -->
		<home-data :homedata="homedata"></home-data>
		<!-- 广告位 -->
		<view class="home-adv m-f-ac">
			<image src="../../static/images/bg1.png" mode="aspectFill" lazy-load class="home-adv-img"></image>
		</view>
		<!-- 功能列表 -->
		<view class="home-list">
			<block v-for="(item, index) in list" :key="index">
				<home-list-item :item="item"></home-list-item>
			</block>
		</view>
	</view>
</template>

<script>
	import homeListItem from '../../components/home/home-list-item.vue'
	import homeInfo from '../../components/home/home-info.vue'
	import otherLogin from '../../components/home/other-login.vue'
	import homeData from '../../components/home/home-data.vue'
	export default {
		data() {
			return {
				loginStatus: false,
				homeinfo: {
					userpic: '../../static/logo.png',
					username: '昵称',
					totalnum: 0,
					todaynum: 0,
				},
				list: [
					{ icon: 'liulan', name: '浏览历史', clicktype: '', url: '' },
					{ icon: 'huiyuanvip', name: '糗百认证', clicktype: '', url: '' },
					{ icon: 'jianpan', name: '审核糗事', clicktype: '', url: '' },
				],
				homedata: [
					{ name: '糗事', num: 0 },
					{ name: '动态', num: 0 },
					{ name: '收藏', num: 0 },
					{ name: '粉丝', num: 0 },
				],
			}
		},
		components: {
			homeListItem,
			homeInfo,
			otherLogin,
			homeData,
		},
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				this.User.navigate({
					url: '../user-set/user-set'
				}, 'navigateTo')
			}
		},
		onShow() {
			this.isLogin()
		},
		methods: {
			isLogin() { // 判断用户是否登录
				if (!this.User.token) {
					this.loginStatus = false
					this.homeinfo = {
						userpic: '',
						username: '',
						totalnum: 0,
						todaynum: 0
					}
					this.homedata[0].num = 0
					this.homedata[1].num = 0
					this.homedata[2].num = 0
					this.homedata[3].num = 0
					return
				}
				// 用户已登录
				this.homeinfo.userpic = this.User.userinfo.userpic
				this.homeinfo.username = this.User.userinfo.username
				this.homeinfo.totalnum = this.User.counts.post_count || 0
				this.homeinfo.todaynum = this.User.counts.todat_posts_count || 0
				this.homedata[0].num = this.User.counts.post_count || 0
				this.homedata[1].num = this.User.counts.post_count || 0
				this.homedata[2].num = this.User.counts.comments_count || 0
				this.homedata[3].num = this.User.counts.withfen_count || 0
				this.loginStatus = true
			},
			openLogin() {
				uni.navigateTo({
					url:'../login/login'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.home-adv {
	padding: 40rpx;
	.home-adv-img {
		border-radius: 20rpx;
		height: 200rpx;
		width: 100%;
	}
}
.home-list {
	padding: 40rpx;
	
}
</style>
